package com.score.controller;

import com.score.pojo.ResponseEntry;
import com.score.pojo.ReturnEntry;
import com.score.pojo.TCheckDorm;
import com.score.service.impl.StuInstructorServiceImpl;
import com.score.util.PinyinUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StuInstructorController {

    @Autowired
    private StuInstructorServiceImpl stuInstructorService;

    /**
     * 根据学生寝室的栋和层返回该层所有寝室
     * @param tung
     * @param layer
     * @return
     */
    @Secured("ROLE_stucadres")
    @PostMapping("/alldormnum")
    public ReturnEntry getAllDormNum(String tung, String layer){
        return stuInstructorService.getAllDormNum(tung,layer);
    }

    /**
     * 学生干部、老师删除寝室信息
     * @return
     */
    @Secured({"ROLE_headmaster", "ROLE_instructor", "ROLE_deputySecretary", "ROLE_dean","ROLE_stucadres"})
    @DeleteMapping("/deletecheckdorm")
    public ReturnEntry deletecheckdorm(Integer checkdormId){
        return stuInstructorService.deletecheckdorm(checkdormId);
    }

    /**
     * 获取寝室成员
     * @param dormNum
     * @return
     */
    @Secured("ROLE_stucadres")
    @PostMapping("/getDormNum")
    public ReturnEntry getDormNum(String dormNum){
        return stuInstructorService.getDormNum(dormNum);
    }

    /**
     * 学生干部插入查寝信息
     * @param checkDorm
     * @return
     */
    @Secured("ROLE_stucadres")
    @PostMapping("/insertcheckdorm")
    public ResponseEntry insertCheckDorm(TCheckDorm checkDorm){
        String headPinYin = PinyinUtils.getHeadPinYin(checkDorm.getCollege());//xxgcxy
        String replace = checkDorm.getDormNum().replace("-", "");//5501
//        rabbitTemplate.convertAndSend(replace,"这是发给学生的");
//        rabbitTemplate.convertAndSend(headPinYin,"这是发给辅导员的");
        return stuInstructorService.insertCheckDorm(checkDorm);
    }
}
